﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MedicalCard.Logic;
using MedicalCard.Data;

namespace MedicalCard.View
{
    public partial class EditPatientForm : Form, IEditPatientView
    {
        public EditPatientPresenter Presenter { get; set; }

        public EditPatientForm()
        {
            InitializeComponent();
            this.Presenter = new EditPatientPresenter(this);
        }

        public EditPatientForm(int patientId)
            : this()
        {
            if (patientId == 0)
            {
                this.Presenter.CreateNew();
            }
            else
            {
                this.Presenter.Load(patientId);
            }
        }

        private void buttonClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        protected void LoadPatientById(int patientId)
        {
            this.Presenter.Load(patientId);
        }

        #region IEditPatientView Members

        public string Number
        {
            get
            {
                return textBoxNumber.Text;
            }
            set
            {
                textBoxNumber.Text = value;
            }
        }

        public string Address
        {
            get
            {
                return textBoxAddress.Text;
            }
            set
            {
                textBoxAddress.Text = value;
            }
        }

        public string Phone
        {
            get
            {
                return textBoxPhone.Text;
            }
            set
            {
                textBoxPhone.Text = value;
            }
        }

        public DateTime Birthdate
        {
            get
            {
                return dateTimePickerBirthdate.Value;
            }
            set
            {
                dateTimePickerBirthdate.Value = value;
            }
        }


        public string PatientName
        {
            get
            {
                return textBoxName.Text;
            }
            set
            {
                textBoxName.Text = value;
            }
        }

        public int PatientId
        {
            set
            {
                labelId.Text = value.ToString();
            }
        }

        public string Message
        {
            get
            {
                return labelMessage.Text;
            }
            set
            {
                labelMessage.Text = value;
            }
        }

        public IEnumerable<Data.Diagnosis> Diagnosis
        {
            set
            {
                dataGridViewDiagnoses.AutoGenerateColumns = false;
                dataGridViewDiagnoses.DataSource = value;
            }
        }

        public IEnumerable<Data.Consultation> Consultations
        {
            set
            {
                dataGridViewConsultations.AutoGenerateColumns = false;
                dataGridViewConsultations.DataSource = value;
            }
        }

        #endregion

        private void buttonSave_Click(object sender, EventArgs e)
        {
            this.Presenter.Save();
        }
    }
}
